﻿using System;
using System.Collections.Generic;
using TestesFixacao.Dominio.Repositorios;

namespace TestesFixacao.WindowsApp.Refatorado.Controls.Shared
{
    public abstract class DataManagerBase<T>
    {
        protected BaseControl Controle;

        protected IRepositorio<T, int> Repositorio = null;

        protected DataManagerBase(IRepositorio<T, int> repositorio, BaseControl control)
        {
            if (repositorio == null)
                throw new ArgumentNullException("repositorio");

            if (control == null)
                throw new ArgumentNullException("control");

            Repositorio = repositorio;
            Controle = control;

            RefreshAll();
        }

        protected void RefreshAll()
        {
            List<T> registros = Repositorio.SelecionaTodos();
            Controle.SetDataSource(registros);
        }

        public BaseControl GetControl()
        {
            RefreshAll();

            return Controle;
        }
    }
}